The present invention relates to a communication protocol stack apparatus and to a method of implementing such an apparatus. More specifically, the present invention relates to a communication protocol stack apparatus and method of implementing such an apparatus in systems with limited memory allocation, access and arrangement operations available.
In data communication networks, it is common to employ several protocols, which are often arranged in layers. For example, it is common for many networks to employ at least some in portion of the ISO Open Systems Interconnection (OSI) Reference Model to deal with communication protocols and network architectures. As is well known, the ISO reference model has seven layers, defined as: the Application layer; the Presentation layer; the Session Layer; the Transport layer; the Network layer; the Data-link layer; and the Physical layer. Generally, it is common that only a subset of the seven layers are employed within a network or that one or more layers are merged.
Each layer of the reference model employs the services of the layer below it and provides services to the layers above it. Thus, for example, the Network layer which is responsible for establishing and maintaining the flow of messages between connected points in the network is dependent upon the Data-link layer to provide character and message synchronization and error correction. The Data-link layer is, in turn, dependent upon the Physical layer to actually transmit and receive information as electrical signals on the network.
An apparatus implementing a collection of protocol layers, such as the seven layers of the OSI Reference Model or a subset or variant thereof, is commonly referred to as a protocol stack. For example, the commonly used TCP/IP protocol is generally implemented as a five layer tack, including: the Application layer; the Transport layer (TCP); the Network layer (IP); the Data-link layer (PPP); and the Physical layer (Ethernet, etc.).
Due to the time critical nature of the services provided by a protocol stack, the performance of the layers is an important factor. Further, the amount of memory resources required by a protocol stack are of concern in many systems. Accordingly, protocol stacks were commonly implemented in early communication systems in machine language. While this provided efficient use of system resources and met real time response standards, protocol stacks can be complex systems to implement and modify, especially for the more advanced protocols now commonly in use, and machine language is not generally preferred for the construction and maintenance of such complex systems.
More recently, protocol stacks have been implemented in the C or C++ programming languages, and similar high level languages. Such high level languages are preferred as they provide a better environment for the development and maintenance of complex systems. Another reason for selecting these languages is that they still provide for processor efficient operations, such as pointer arithmetic, and fine grained memory allocation and management operations, via the malloc family of system calls for example, which allow for efficient memory usage. Further, data structures such as C unions and structs are available which allow the implementer of the protocol stack to explicitly control the representation of data structures in memory.
More recently, much interest and development has occurred with the Java programming language. Java is an interpreted language which comprises a series of byte codes that are compiled from Java source code. These byte codes are usually interpreted (or in some cases compiled by a Just in Time compiler) and executed by a Java Virtual Machine (VM) which is a program executing on the target platform. A Java program can thus be executed on any computer system for which a Java VM exists.
However, Java offers some challenges to those wishing to implement many types of systems. For example, unlike machine language, C, C++ and many other programming languages, for simplicity of coding and other reasons, such as security and automatic garbage collections, Java does not provide any mechanism for explicitly defining the representation of objects in memory, nor does Java guarantee a specific representation for defined data types in memory, i.e.xe2x80x94while a short integer data type is defined in the Java specification as sixteen bits for calculation purposes, it is legal that it can be represented in memory as thirty-two bits. Java also does not support the explicit allocation or deallocation of blocks of memory or the traversing of memory structures using pointer arithmetic. In fact, one of Java""s features is its automatic xe2x80x9cgarbage collectionxe2x80x9d wherein implicitly deallocated memory is reclaimed and free memory is consolidated. During a garbage collection cycle the memory representation of an object can change from what it was prior to the cycle.
Java""s lack of explicit memory allocation, deallocation and traversing features and its lack of a mechanism to explicitly define the representation of an object in memory has made it difficult to implement a protocol stack which provides acceptable performance with acceptable memory requirements.
Generally, the passing of information between layers in a protocol stack implemented in Java can quickly result in the fragmentation of memory in the Java VM and the consumption of that memory by unreferenced objects. Such fragmentation and consumption can adversely affect the performance of the stack due to the relatively excessive memory allocations and data copy operations performed at each layer. In particular, implementations employing the passing of message objects between layers have been found to be inefficient, and often unacceptable, due to the high overheads involved in allocating new memory, garbage collecting unreferenced objects and streaming objects to physical devices.
It is therefore desired to have a protocol stack apparatus and method of implementing such a stack apparatus which can be relatively efficiently implemented in systems, such as those employing the Java language, which have limited memory allocation, access and arrangement operations available.
It is an object of the present invention to provide a novel protocol stack apparatus and method of implementing such a protocol stack apparatus which obviates or mitigates at least one disadvantage of the prior art.
According to a first aspect of the present invention, there is provided a communication protocol stack apparatus, comprising: a first protocol layer; at least one protocol layer below said first protocol layer in said stack; a binding mechanism to bind said first and each said at least one protocol layers together into a protocol stack, said binding mechanism determining for each layer of said protocol stack in turn, from a lowest layer to said first layer, an aggregate maximum header length and aggregate trailer length for said layer and each layer below said layer; a buffer allocation mechanism to allocate at least one memory buffer for each layer of said protocol stack, said at least one buffer of each layer having a length at least equal to the sum of said aggregated maximum header and trailer lengths determined for said layer and a selected maximum data payload size; a buffer passing mechanism to pass an allocated buffer from a higher layer to a lower layer in said protocol stack, said buffer passing mechanism: for a protocol layer, copying data to be transmitted from said higher layer into said buffer starting at a position offset from the first position of said buffer by a number of positions equal to said aggregated maximum header length determined for said higher layer, copying an encapsulated header for said higher layer into said buffer at the positions immediately preceding said data copied to said buffer and copying an encapsulating trailer for said higher layer into said buffer at the positions immediately following said data and setting a first indicator to the start position of said encapsulating header in said buffer and setting a second indicator to the end position of said encapsulating trailer in said buffer; and for each lower layer in said protocol stack, in turn, copying an encapsulating header for said lower layer into said buffer at the positions immediately preceding said position indicated by said first indicator and copying an encapsulating trailer for said lower layer into said buffer at the positions immediately following said position indicated by said second indicator and updating said first indicator to the start position of said encapsulating header for said lower layer in the buffer and updating said second indicator to the end position of said encapsulating trailer for said lower layer in the buffer.
According to another aspect of the present invention, there is provided a method of implementing a communication protocol stack of at least a higher protocol layer and a lower protocol layer, comprising the steps of:
(i) determining for each protocol layer of said stack the maximum aggregate header and aggregate trailer length for the layer and each lower layer;
(ii) allocating, for each protocol layer of the stack, at least one memory buffer having a length at least equal to the sum of the determined maximum aggregate header and maximum aggregate trailer lengths for the layer and a selected maximum data payload length;
(iii) receiving at a first layer data to be transmitted from said stack;
(iv) selecting an available buffer from said at least one memory buffer allocated for said first layer;
(v) copying information representing a portion of said received data, not exceeding said selected maximum data payload length, to said buffer starting at a position offset from the start of said buffer by a length equal to said determined maximum header length for said protocol layer;
(vi) copy information representing an encapsulating header for said protocol layer to the positions in said buffer immediately preceding said information previously copied into said buffer and copying information representing an encapsulating trailer for said layer to the positions in said buffer immediately following said information previously copied into said buffer;
(vii) setting a first indicator to indicate the first position in said buffer of said information representing said encapsulating header of said protocol layer and setting a second indicator to indicate the last position in said buffer of said information representing said encapsulating trailer for said protocol layer;
(viii) passing said buffer to the next lower protocol layer in said stack;
(ix) repeating steps (vi) through (viii) until information from the lowest layer has been copied into said buffer and said first and second indicators set accordingly; and
(x) copying the information in said buffer, between the position indicated by said first indicator and the position indicated by said second indicator to a data transmission device.
According to another aspect of the present invention, there is provided a method of constructing and using a protocol stack comprising at least two protocol layers, comprising:
(i) for each layer of said stack determining a maximum length comprising the sum of a pre-selected maximum data payload length and a maximum aggregate header length and a maximum aggregate trailer length, said aggregates including each layer in said protocol stack below said layer;
(ii) for each layer allocating at least one buffer of said maximum length;
(iii) receiving data to be transmitted at a layer and copying said data into said at least one buffer at a position offset from the start of the buffer by said maximum aggregate header length determined for said layer, copying into said buffer immediately before said copied data a header for said layer, copying into said buffer immediately after said copied data a trailer for said layer and setting indicators of the positions within said buffer of the start of said header and the end of said trailer;
(iv) passing said buffer to a lower layer of said stack, said lower layer copying into said buffer immediately preceding the start of the header in said buffer as indicated by said indicator a header for said layer and copying into said buffer immediately after the end of the trailer in said buffer as indicated by said indicator a trailer for said layer and updating said indicators of the positions of the start of the headers and the end of the trailers accordingly;
(v) at the lowest level of said stack, copying to a data transmission device said data between said indicators.
The present invention provides a communication protocol stack apparatus and method which determines the aggregated maximum encapsulating header and trailer lengths for each layer of the stack and pre-allocates, for each layer, one or more buffers of a length equal to the sum of the determined maximum header and trailer lengths and a selected maximum data length. The layer of the stack receiving the data copies it into one of the pre-allocated buffers for that layer at a position offset by the determined maximum aggregate header length. The layer copies the encapsulating header to a position immediately before the location of the data in the buffer and copies the encapsulating trailer to a position immediately after the data in the buffer. The layer also sets a reference to the position of the start of the encapsulating header in the buffer and the position of the end of the encapsulating trailer in the buffer. The next lower layer of the protocol stack copies its encapsulating header into the buffer before the position indicated by the reference to the start of the header and the updates the reference accordingly. In a similar manner, the lower layer of the protocol stack copies its encapsulating trailer after the end of the previous layer""s trailer, as indicated by the reference to the end of the trailer, and then updates that reference accordingly. The process is repeated until the lowest layer is reached where the array of headers, data and trailers between the two references is copied to a physical device for transmission.